package com.ourteam.product.ui.dao.impl;

import com.ourteam.product.ui.dao.IProductUIImageDAO;
import com.ourteam.product.ui.dao.ProductUIImage;
import com.ourteam.product.ui.dao.ProductUIImageDAOQueryBean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.jdbc.core.RowMapper;

/**
 * Template Name : DAO服务对象 Template Version : 1 Template Last Modfiy Date : Fri Nov 17 11:00:11 CST
 * 2017 Auto Generate Date : 2018-12-14 15:15:19 Warning ! This file will be overwrite when
 * regenerate !
 */
public class AbstractProductUIImageDAOJdbcImpl extends AbstractSpringDAO
    implements IProductUIImageDAO {

  public static final String[] ENTITY_FIELDS =
      new String[] {
        Id,
        DomainId,
        ImageCode,
        ImagePath,
        ImageWidth,
        ImageHeight,
        ImageType,
        LastModifyUser,
        LastModifyTime,
        Status,
        Remarks,
        ImageContent,
        DomainCode,
        DomainName
      };

  public static final String[] ENTITY_PROPERTIES =
      new String[] {
        _DataObjectProperty.Id,
        _DataObjectProperty.DomainId,
        _DataObjectProperty.ImageCode,
        _DataObjectProperty.ImagePath,
        _DataObjectProperty.ImageWidth,
        _DataObjectProperty.ImageHeight,
        _DataObjectProperty.ImageType,
        _DataObjectProperty.LastModifyUser,
        _DataObjectProperty.LastModifyTime,
        _DataObjectProperty.Status,
        _DataObjectProperty.Remarks,
        _DataObjectProperty.ImageContent,
        _DataObjectProperty.DomainCode,
        _DataObjectProperty.DomainName
      };

  public static final String[] ENTITY_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};

  private static String relatedJoinSQL = null;

  private static String basicFilterSQL = null;

  private DataAccessObjectHelper<ProductUIImage, ProductUIImageDAOQueryBean> daoHelper;

  public AbstractProductUIImageDAOJdbcImpl() {
    super();
    daoHelper = new DataAccessObjectHelper<ProductUIImage, ProductUIImageDAOQueryBean>(this);
  }

  protected String getEntityName() {
    return EntityName;
  }

  protected String[] getEntityFields() {
    return ENTITY_FIELDS;
  }

  protected String[] getEntityProperties() {
    return ENTITY_PROPERTIES;
  }

  protected String[] getEntityPKFields() {
    return ENTITY_PK_FIELDS;
  }

  protected String[] getEntityAutoGenPKFields() {
    return ENTITY_AUTO_GEN_PK_FIELDS;
  }

  protected String[] getEntityUniqueFields() {
    return ENTITY_UNIQUE_FIELDS;
  }

  protected String getBaiscQueryFilter() {

    if (basicFilterSQL == null) {
      StringBuffer basicFilterSQLbuffer = new StringBuffer();

      basicFilterSQL = basicFilterSQLbuffer.toString();
    }

    return basicFilterSQL;
  }

  protected String getRelatedJoinSQL() {

    if (relatedJoinSQL == null) {
      StringBuffer relatedJoinSQLBuffer = new StringBuffer();

      relatedJoinSQLBuffer
          .append(" LEFT JOIN ")
          .append(com.ourteam.product.ui.dao.IProductUIDomainDAO.EntityName)
          .append(" PRODUCT_UI_DOMAIN ");

      relatedJoinSQLBuffer.append(" ON ( ");

      relatedJoinSQLBuffer.append(
          StringUtils.replace(
              com.ourteam.product.ui.dao.IProductUIDomainDAO.Id,
              com.ourteam.product.ui.dao.IProductUIDomainDAO.EntityName + ".",
              "PRODUCT_UI_DOMAIN."));
      relatedJoinSQLBuffer.append(" = ").append(DomainId);

      relatedJoinSQLBuffer.append(" ) ");

      relatedJoinSQL = relatedJoinSQLBuffer.toString();
    }

    return relatedJoinSQL;
  }

  /**
   * Check Data Unique
   *
   * @param aProductUIImage
   * @throws Exception
   */
  public boolean checkIsUnique(ProductUIImage aProductUIImage) throws Exception {

    if (aProductUIImage == null) {
      return true;
    }

    List valueList = new ArrayList();

    List pkValueList = new ArrayList();

    pkValueList.add(aProductUIImage.getId());

    return isUnique(
        valueList.toArray(new Object[valueList.size()]),
        pkValueList.toArray(new Object[pkValueList.size()]));
  }

  /**
   * Insert Data
   *
   * @param aProductUIImage
   * @throws Exception
   */
  public void insert(ProductUIImage aProductUIImage) throws Exception {

    PropertyUtils.setProperty(
        aProductUIImage,
        _DataObjectProperty.LastModifyTime,
        new java.sql.Timestamp(System.currentTimeMillis()));

    super.doInsert(aProductUIImage);
  }

  /**
   * Batch Insert Datas
   *
   * @param aProductUIImage
   * @throws Exception
   */
  public void batchInsert(ProductUIImage[] aProductUIImages) throws Exception {

    super.doBatchInsert(aProductUIImages);
  }

  /**
   * Delete Data
   *
   * @param final long id *
   * @throws Exception
   */
  public void delete(final long id) throws Exception {

    super.doDeleteById(new Object[] {new Long(id)});
  }

  /**
   * Delete Datas
   *
   * @param queryBean
   * @throws Exception
   */
  public void delete(ProductUIImageDAOQueryBean queryBean) throws Exception {

    super.doDeleteByQuery(queryBean);
  }

  public void delete(ProductUIImage aProductUIImage) throws Exception {

    delete(aProductUIImage.getId());
  }

  /**
   * Update Data Selective
   *
   * @param aProductUIImage
   * @throws Exception
   */
  public void update(ProductUIImage aProductUIImage) throws Exception {

    PropertyUtils.setProperty(
        aProductUIImage,
        _DataObjectProperty.LastModifyTime,
        new java.sql.Timestamp(System.currentTimeMillis()));

    if (aProductUIImage.getId() == 0) {
      throw new Exception("Can not update object data whith out primary key value");
    }

    super.doUpdate(aProductUIImage);

    ProductUIImage tempObj = findById(aProductUIImage.getId());

    if (tempObj != null) {
      PropertyUtils.copyProperties(aProductUIImage, tempObj);
    }
  }

  /**
   * Batch Update Datas
   *
   * @param aProductUIImages[]
   * @throws Exception
   */
  public void batchUpdate(ProductUIImage[] aProductUIImages) throws Exception {

    super.doBatchUpdate(aProductUIImages);
  }

  /**
   * Update Data By Condictions
   *
   * @param aProductUIImage
   * @param aValueCriteria
   * @param aTransaction
   * @throws Exception
   */
  public void update(ProductUIImage aProductUIImage, ProductUIImageDAOQueryBean aQueryBean)
      throws Exception {

    PropertyUtils.setProperty(
        aProductUIImage,
        _DataObjectProperty.LastModifyTime,
        new java.sql.Timestamp(System.currentTimeMillis()));

    super.doUpdateByQuery(aProductUIImage, aQueryBean);
  }

  /**
   * Update Data By Condictions
   *
   * @param aQueryBean
   * @throws Exception
   */
  public void update(ProductUIImageDAOQueryBean aQueryBean) throws Exception {
    super.doUpdateByQuery(aQueryBean);
  }

  protected void checkNullValue(ProductUIImage aProductUIImage) throws Exception {

    if (aProductUIImage.getImageCode() == null) {
      throw new Exception("The ProductUIImage.imageCode value is not allow NULL");
    }

    if (aProductUIImage.getImagePath() == null) {
      throw new Exception("The ProductUIImage.imagePath value is not allow NULL");
    }

    if (aProductUIImage.getImageType() == null) {
      throw new Exception("The ProductUIImage.imageType value is not allow NULL");
    }

    if (aProductUIImage.getLastModifyUser() == null) {
      throw new Exception("The ProductUIImage.lastModifyUser value is not allow NULL");
    }

    if (aProductUIImage.getLastModifyTime() == null) {
      throw new Exception("The ProductUIImage.lastModifyTime value is not allow NULL");
    }

    if (aProductUIImage.getStatus() == null) {
      throw new Exception("The ProductUIImage.status value is not allow NULL");
    }

    if (aProductUIImage.getRemarks() == null) {
      throw new Exception("The ProductUIImage.remarks value is not allow NULL");
    }

    if (aProductUIImage.getDomainCode() == null) {
      throw new Exception("The ProductUIImage.domainCode value is not allow NULL");
    }

    if (aProductUIImage.getDomainName() == null) {
      throw new Exception("The ProductUIImage.domainName value is not allow NULL");
    }

    if (aProductUIImage.getImageContent() == null) {
      throw new Exception("The ProductUIImage.imageContent value is not allow NULL");
    }
  }

  /**
   * Get Data By ID
   *
   * @param final long id * @return ${businessObject.name}
   * @throws Exception
   */
  public ProductUIImage findById(final long id) throws Exception {

    ProductUIImageDAOQueryBean queryBean = new ProductUIImageDAOQueryBean();

    ProductUIImageDAOQueryBean.Criteria criteria = queryBean.createCriteria();

    criteria.andIdEqualTo(id);

    // queryBean.setDistinct(true);

    ProductUIImage[] ProductUIImages = query(queryBean);

    if (ProductUIImages.length == 0) {
      return null;
    } else {
      return ProductUIImages[0];
    }
  }

  /**
   * Query Data
   *
   * @param queryBean
   * @return ProductUIImage[]
   * @throws Exception
   */
  public ProductUIImage[] query(ProductUIImageDAOQueryBean queryBean) throws Exception {

    List result = super.doQuery(queryBean, new JdbcProductUIImageRowMapper());

    return (ProductUIImage[]) result.toArray(new ProductUIImage[result.size()]);
  }

  /**
   * Query ${businessObject.name} Selective
   *
   * @param queryBean
   * @return Map[]
   * @model
   * @throws Exception
   */
  public Map<String, Object>[] querySelective(ProductUIImageDAOQueryBean queryBean)
      throws Exception {

    if (queryBean.getSelectProperties().isEmpty()) {
      queryBean.addAllSelectProperties();
    }

    return super.doQuerySelective(queryBean);
  }

  /**
   * Query Data Count
   *
   * @param queryBean
   * @return int
   * @throws Exception
   */
  public int queryCount(ProductUIImageDAOQueryBean queryBean) throws Exception {

    return super.doQueryCount(queryBean);
  }

  public void synchronize(ProductUIImage[] aProductUIImages, ProductUIImageDAOQueryBean queryBean)
      throws Exception {
    daoHelper.synchronize(aProductUIImages, queryBean);
  }

  public void synchronize(
      ProductUIImage[] aProductUIImages,
      ProductUIImageDAOQueryBean queryBean,
      net.dao.IDataAccessInterface.ISynchronizeCallback<ProductUIImage> callBack)
      throws Exception {
    daoHelper.synchronize(aProductUIImages, queryBean, callBack);
  }

  public static class JdbcProductUIImageRowMapper implements RowMapper<ProductUIImage> {

    public ProductUIImage mapRow(ResultSet resultSet, int arg1) throws SQLException {
      ProductUIImage object = new ProductUIImage();

      int columnIndex = 1;

      int __dataType;

      try {

        Object id = null;

        id = resultSet.getObject(columnIndex++);

        object.setIdNull(resultSet.getBoolean(columnIndex++));

        if (id != null) {

          setBeanValue(object, _DataObjectProperty.Id, id);
        }

        Object domainId = null;

        domainId = resultSet.getObject(columnIndex++);

        object.setDomainIdNull(resultSet.getBoolean(columnIndex++));

        if (domainId != null) {

          setBeanValue(object, _DataObjectProperty.DomainId, domainId);
        }

        Object imageCode = null;

        imageCode = resultSet.getObject(columnIndex++);

        object.setImageCodeNull(resultSet.getBoolean(columnIndex++));

        if (imageCode != null) {

          setBeanValue(object, _DataObjectProperty.ImageCode, imageCode);
        }

        Object imagePath = null;

        imagePath = resultSet.getObject(columnIndex++);

        object.setImagePathNull(resultSet.getBoolean(columnIndex++));

        if (imagePath != null) {

          setBeanValue(object, _DataObjectProperty.ImagePath, imagePath);
        }

        Object imageWidth = null;

        imageWidth = resultSet.getObject(columnIndex++);

        object.setImageWidthNull(resultSet.getBoolean(columnIndex++));

        if (imageWidth != null) {

          setBeanValue(object, _DataObjectProperty.ImageWidth, imageWidth);
        }

        Object imageHeight = null;

        imageHeight = resultSet.getObject(columnIndex++);

        object.setImageHeightNull(resultSet.getBoolean(columnIndex++));

        if (imageHeight != null) {

          setBeanValue(object, _DataObjectProperty.ImageHeight, imageHeight);
        }

        Object imageType = null;

        imageType = resultSet.getObject(columnIndex++);

        object.setImageTypeNull(resultSet.getBoolean(columnIndex++));

        if (imageType != null) {

          setBeanValue(object, _DataObjectProperty.ImageType, imageType);
        }

        Object lastModifyUser = null;

        lastModifyUser = resultSet.getObject(columnIndex++);

        object.setLastModifyUserNull(resultSet.getBoolean(columnIndex++));

        if (lastModifyUser != null) {

          setBeanValue(object, _DataObjectProperty.LastModifyUser, lastModifyUser);
        }

        Object lastModifyTime = null;

        __dataType = resultSet.getMetaData().getColumnType(columnIndex);

        if (__dataType == java.sql.Types.DATE
            || __dataType == java.sql.Types.TIME
            || __dataType == java.sql.Types.TIMESTAMP) {
          lastModifyTime = resultSet.getTimestamp(columnIndex++);

        } else {
          lastModifyTime = resultSet.getObject(columnIndex++);
        }

        object.setLastModifyTimeNull(resultSet.getBoolean(columnIndex++));

        if (lastModifyTime != null) {

          setBeanValue(object, _DataObjectProperty.LastModifyTime, lastModifyTime);
        }

        Object status = null;

        status = resultSet.getObject(columnIndex++);

        object.setStatusNull(resultSet.getBoolean(columnIndex++));

        if (status != null) {

          setBeanValue(object, _DataObjectProperty.Status, status);
        }

        Object remarks = null;

        remarks = resultSet.getObject(columnIndex++);

        object.setRemarksNull(resultSet.getBoolean(columnIndex++));

        if (remarks != null) {

          setBeanValue(object, _DataObjectProperty.Remarks, remarks);
        }

        Object imageContent = null;

        imageContent = resultSet.getObject(columnIndex++);

        object.setImageContentNull(resultSet.getBoolean(columnIndex++));

        if (imageContent != null) {

          setBeanValue(object, _DataObjectProperty.ImageContent, imageContent);
        }

        Object domainCode = null;

        domainCode = resultSet.getObject(columnIndex++);

        object.setDomainCodeNull(resultSet.getBoolean(columnIndex++));

        if (domainCode != null) {

          setBeanValue(object, _DataObjectProperty.DomainCode, domainCode);
        }

        Object domainName = null;

        domainName = resultSet.getObject(columnIndex++);

        object.setDomainNameNull(resultSet.getBoolean(columnIndex++));

        if (domainName != null) {

          setBeanValue(object, _DataObjectProperty.DomainName, domainName);
        }

        return object;
      } catch (Exception e) {
        throw new SQLException(e.getMessage());
      }
    }
  }
}
